package newFeatures.streamAPI;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * Created with IntelliJ IDEA.
 * ClassName: StreamAPITest
 * Package: newFeatures.streamAPI
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-12-24
 * Time: 23:47
 */

public class StreamAPITest {



    //创建Stream流的第三种方式
    public static void main(String[] args) {
        //数据没有呈现出一种容器
        Stream<Integer> stream = Stream.of(1, 2, 3, 4, 5);

    }


    //通过数组的方式创建stream对象
    public static void main2(String[] args) {
        Integer[] arr = new Integer[]{1,2,3,4,5};
        //stream不存储数据
        Stream<Integer> stream = Arrays.stream(arr);

        int[] arr1 = new int[]{1,2,3,4,5,6};
        IntStream stream1 = Arrays.stream(arr1);

        System.out.println(stream);
        System.out.println(stream1);

    }



    //创建方式一  通过集合创建
    public static void main1(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        //通过list 调用stream方法 直接返回stream实例 返回一个顺序流 list添加的顺序
        Stream<Integer> stream = list.stream();

        //返回并行的stream流
        Stream<Integer> integerStream = list.parallelStream();

        System.out.println(stream);
        System.out.println(integerStream);


    }

}
